package com.rrjjg.config.configuration;


import com.alibaba.druid.pool.DruidDataSource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.config.server.environment.JdbcEnvironmentProperties;
import org.springframework.cloud.config.server.environment.JdbcEnvironmentRepository;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.jdbc.core.JdbcTemplate;

@Slf4j
@Configuration
public class JdbcConfig {

    @Bean
    public JdbcEnvironmentRepository jdbcEnvironmentRepository( JdbcTemplate jdbcTemplate,JdbcEnvironmentProperties properties){
        return new JdbcEnvironmentRepository(jdbcTemplate,properties);
    }

    @Bean
    public JdbcEnvironmentProperties properties(){
        return new JdbcEnvironmentProperties();
    }

    @Bean
    public JdbcTemplate jdbcTemplate(DruidDataSource dataSource){

        log.info("druidDataSourece info \n\turl={}\n\tusername={}\n\tdriverClassName={}\n\tinitialSize={}\n\t" +
                "maxActive={}\n\tmaxWait={}\n\t",
                dataSource.getUrl(),
                dataSource.getUsername(),
                dataSource.getDriverClassName(),
                dataSource.getInitialSize(),
                dataSource.getMaxActive(),dataSource.getMaxWait());
        return new JdbcTemplate(dataSource);
    }


}
